/**
 * Company : SIANGKLOM.
 * Created By : Chatree Siangklom
 * Created On : Nov 6, 2013  10:14:34 AM 
 * e-Mail : dr_chatree@hotmail.com
 * Mobile Phone : (+66) 087-921-5115
 * Package Name : com.tis.utilitys
 * File Name : PropertiesUtility.java
 * TODO
 */
package com.tis.utilitys;

import java.io.IOException;
import java.util.Properties;
import promis.utility.CommonService;

/**
 * @author Chatree Siangklom of Administrator
 * Date =Nov 6, 2013 : 10:14:34 AM 
 * CreateBy=Chatree Siangklom
 * 
 * PropertiesUtility
 * TODO
 */
public class PropertiesUtility {

	String path;
	
	/**
	 * @param path the path to set
	 * Date =Nov 6, 2013 : 10:15:02 AM 
	 * CreateBy=Chatree Siangklom
	 *  PropertiesUtility.java String
	 * TODO
	 */
	public void setPath(String path) {
		this.path = path;
	}
	
	public PropertiesUtility(){}
	
	/**
	 * Date =Nov 6, 2013 : 10:14:34 AM 
	 * CreateBy=Chatree Siangklom
	 * PropertiesUtility
	 * TODO
	 */
	public PropertiesUtility(String path) {
		this.path = path;
	}
	
	/**
	 * Date =Nov 6, 2013 : 10:48:26 AM 
	 * CreateBy=Chatree Siangklom
	 * String
	 * TODO
	 * @param key
	 * @return
	 * @throws Exception
	 * @throws IOException
	 */
	public String GetConfigDBValue(String key) throws Exception, IOException {
		try{
			Properties prop = new Properties();
			prop.load(this.getClass().getClassLoader().getResourceAsStream("database/database-oracle.properties"));
	        //Print required values
	        if(!CommonService.IsNull(key)){
	        	System.out.println(prop.get(key));
	        	return CommonService.IsNullRNull(prop.get(key));
	        }
		}catch(Exception e)
		{			
			e.printStackTrace();
			throw e;
		}
		return null;
	}
	
	/**
	 * Date =Nov 6, 2013 : 10:48:18 AM 
	 * CreateBy=Chatree Siangklom
	 * String
	 * TODO
	 * @param key
	 * @return
	 * @throws Exception
	 * @throws IOException
	 */
	public String GetConfigInterfaceSecurityValue(String key) throws Exception, IOException {
		try{
			Properties prop = new Properties();
			prop.load(this.getClass().getClassLoader().getResourceAsStream("database/security.properties"));
	        //Print required values
	        if(!CommonService.IsNull(key)){
	        	System.out.println(prop.get(key));
	        	return CommonService.IsNullRNull(prop.get(key));
	        }
		}catch(Exception e)
		{			
			e.printStackTrace();
			throw e;
		}
		return null;
	}
	
	/**
	 * Date =Nov 6, 2013 : 10:19:04 AM 
	 * CreateBy=Chatree Siangklom
	 * String
	 * TODO
	 * @param path example : database/database-oracle.properties
	 * @param key
	 * @return
	 * @throws Exception
	 * @throws IOException
	 */
	public String GetConfigValue(String path, String key) throws Exception, IOException {
		try{
			Properties prop = new Properties();
			if(!CommonService.IsNull(path)){
				prop.load(this.getClass().getClassLoader().getResourceAsStream(path));
		        //Print required values
		        if(!CommonService.IsNull(key)){
		        	System.out.println(prop.get(key));
		        	return CommonService.IsNullRNull(prop.get(key));
		        }
			}
		}catch(Exception e)
		{			
			e.printStackTrace();
			throw e;
		}
		return null;
	}

}
